<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>代客充值</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/dtree.css" media="all" />
    <link rel="stylesheet" href="/resources/layui_ext/dtree/font/dtreefont.css" media="all" />

</head>
<body class="childrenBody">


<div style="padding: 5px" id="chargeDiv">
    <form action="" method="post" class="layui-form layui-form-pane" id="chargeFrm" lay-filter="chargeFrm">
        <div class="layui-form-item">
            <label class="layui-form-label">充值账号：</label>
            <div class="layui-input-block">
                <input type="text" name="phoneNumber" lay-verify="required|number" autocomplete="off" placeholder="请输入充值账号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">充值金额</label>
            <div class="layui-input-block">
                <input type="text" name="chargeNum" lay-verify="required|number" autocomplete="off" placeholder="请输入充值金额" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-filter="doSubmit" lay-submit="" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>确定</button>
                <button type="reset" class="layui-btn layui-btn-warm" lay-submit="" lay-filter="doCancel" id="doCancel"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>

        <input type="file" name="file" id="upload">

    </form>

    <div class="site-demo-upload">
        <img id="LAY_demo_upload" src="/layer/images/tong.jpg">
        <div class="site-demo-upbar">
            <input type="file" name="file" class="layui-upload-file" id="test">
        </div>
    </div>
</div>
<!-- 充值弹出层结束 -->



<script type="text/javascript" src="/resources/layui/layui.js"></script>
<script type="text/javascript">
    layui.extend({
        dtree: '/resources/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['jquery','form','layer','upload'],function(){
        var $=layui.jquery;
        var form=layui.form;
        var layer=layui.layer;

        //初始化富文本



        $("#upload").on('change', function (event) {
            var $file = event.currentTarget;
            var formData;
            var file = $file.files;
            formData = new FormData();
            //formData.append(file[0].name, file[0]);
            formData.append("file", file[0]);

            $.ajax({
                url: '/oss/doFileUpload',
                type: 'POST',
                dataType: 'json',
                data: formData,
                contentType: false,
                processData: false
            })
                .done(data => {
                   console.log("上传成功");
                })
                .fail(data => {
                    console.log(data);
                });
        });

            form.on("submit(doSubmit)",function(data) {

                layer.confirm('你确定要给【'+ data.field.phoneNumber+'】充值' + data.field.chargeNum + '吗?', {icon: 3, title:'提示'}, function(index){
                $.post("/groupInfo/charge", data.field, function (res) {
                    if (res.code == 200) {

                    }
                    layer.msg(res.msg);
                    //layer.close(mainIndex);
                })
                return false;
            });
        });



        //充值
        function charge(data){
            mainIndex=layer.open({
                type:1,
                content:$("#chargeDiv"),
                area:['800px','300px'],
                title:'充值',
                success:function(){

                    $("#chargeFrm")[0].reset();
                    $("#companyname").html(data.gpName);
                    //装载新的数据
                    form.val("chargeFrm",data);
                    url="/groupInfo/charge";
                }
            });
        }


    });
</script>

</body>
</html>